package main

import "fmt"

func main() {
	s := "anagram"
	t := "nagaram"
	fmt.Println(isAnagram(s, t))
}

func isAnagram(s string, t string) bool {
	if len(s) != len(t) {
		return false
	}

	m := make(map[byte]int, len(s))
	for i := 0; i < len(s); i++ {
		if v, ok := m[s[i]]; ok {
			m[s[i]] = v + 1
		} else {
			m[s[i]] = 1
		}

		if v, ok := m[t[i]]; ok {
			m[t[i]] = v - 1
		} else {
			m[t[i]] = -1
		}
	}

	for _, v := range m {
		if v < 0 {
			return false
		}
	}

	return true
}
